<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ include file="/views/include/taglib.jsp"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<%@ include file="/views/include/nocachehead.jsp"%>
<%@ include file="/views/include/statusbar.jsp"%>
<script type="text/javascript" src="http://api.map.baidu.com/api?v=1.2"></script>
<script type="text/javascript" src="http://j.maxmind.com/app/geoip.js"></script>
<script type="text/javascript"
	src="${pageContext.request.contextPath}/js/map.js"></script>
<script src="http://int.dpool.sina.com.cn/iplookup/iplookup.php?format=js" type="text/javascript"></script>
</head>

<script type="text/javascript">
	function getCountries(userCountry, userProvince, userCity) {
		var country = document.getElementById("country");
		$.ajax({
			url : "/skyline/site/getCountries.html",
			type : "POST",
			dataType : "json",
			contentType : "application/x-www-form-urlencoded; charset=utf-8",
			success : function(msg) {
				for ( var i = 0; i < msg.length; i++) {
					var varItem = new Option(msg[i].name, msg[i].name + "-"
							+ msg[i].id);
					if (msg[i].name == userCountry) {
						varItem.selected = true;
					}
					country.options.add(varItem);
				}
				getProvinces(userProvince, userCity);
			}
		});
	}
	function getProvinces(userProvince, userCity) {
		var province = document.getElementById("province");
		var country = document.getElementById("country").value;
		var countryId = country.split("-")[1];
		$.ajax({
			url : "/skyline/site/getSubSites.html",
			type : "POST",
			data : "siteId=" + countryId,
			dataType : "json",
			contentType : "application/x-www-form-urlencoded; charset=utf-8",
			success : function(msg) {
				province.options.length = 0;
				for ( var i = 0; i < msg.length; i++) {
					var varItem = new Option(msg[i].name, msg[i].name + "-"
							+ msg[i].id);
					if (msg[i].name == userProvince) {
						varItem.selected = true;
					}
					province.options.add(varItem);
				}
				getCities(userCity)
			}
		});
	}
	function getCities(userCity) {
		var city = document.getElementById("city");
		var province = document.getElementById("province").value;
		var provinceId = province.split("-")[1];
		$.ajax({
			url : "/skyline/site/getSubSites.html",
			type : "POST",
			data : "siteId=" + provinceId,
			dataType : "json",
			contentType : "application/x-www-form-urlencoded; charset=utf-8",
			success : function(msg) {
				city.options.length = 0;
				for ( var i = 0; i < msg.length; i++) {
					var varItem = new Option(msg[i].name, msg[i].name + "-"
							+ msg[i].id);
					if (msg[i].name == userCity) {
						varItem.selected = true;
					}
					city.options.add(varItem);
				}
			}
		});
	}
	function checkExit() {
		$.ajax({
			url : "/skyline/spot/isexit.html",
			type : "POST",
			data : "name=" + $('#name').val(),
			dataType : "json",
			contentType : "application/x-www-form-urlencoded; charset=utf-8",
			success : function(msg) {
				//alert(msg);
				if (msg) {
					alert("存在该景点");
				}
			}
		});

	}
	function CheckCertCode(FieldID, FieldName) {
		var Field = document.getElementById(FieldID);
		var Msg = document.getElementById(FieldID + "_div");
		var Img = document.getElementById(FieldID + "_img");
		var Font = document.getElementById(FieldID + "_font");
		if (Field.value == "") {
			empity(Msg, Img, Font, FieldName);
			return false;
		} else {
			if (submitted == false) {
				$.ajax({
					type : "POST",
					url : 'certcode/verify/' + Field.value + '.html',
					data : null,
					success : function(msg) {
						if (msg == "true") {
							Msg.style.display = "block";
							Img.src = success_gif;
							Font.innerHTML = "";
						} else {
							Msg.style.display = "block";
							Img.src = fail_gif;
							Font.color = fail_font_color;
							Font.innerHTML = "验证码错误";
						}
					}
				});
			}
			if (Font.innerHTML == "")
				return true;
			else
				return false;
		}
	}
	function ChangCertPic() {
		var certpic = document.getElementById('certpic');
		certpic.src = 'util/MakeCertPic.jpg?a=' + Math.random();
	}
	$(document).ready(
			

			function() {
				getCountries(remote_ip_info.country, remote_ip_info.province+"省", remote_ip_info.city+"市");
			//	loadMap("mapContainer", new BMap.Point(geoip_longitude(),geoip_latitude()));
			loadMap("mapContainer",remote_ip_info.city );
				var oldmark;
				map.addEventListener("click", function(e) {
					// alert(e.point.lng + ", " + e.point.lat);  
					$("#longitude").val(e.point.lng);
					$("#latitude").val(e.point.lat);
					map.removeOverlay(oldmark);
					var marker = new BMap.Marker(e.point); // 创建标注
					oldmark = marker;
					addMarkerOnMap(map, marker);
				});
			});
</script>
<body>
	<br>
	<br>
	<br>



	<form id="discoverySpotForm" name="discoverySpotForm"
		action="${pageContext.request.contextPath}/spot/discovery.html"
		method="post">
		<c:out value="${requestScope.errMsg}" escapeXml="false" />

		<label>地点名称：</label> <input id="name" name="name" onBlur="checkExit()" />
		<input type="button" id="serch" value='查找'
			onclick="serchFromCityByName($('#city').val(),$('#name').val(),null)">
		<br> <label> 分类：</label> <select name="category">
			<option value="VIEWPOINT">景点</option>
			<option value="OTHER">其他</option>
		</select> <br> <label>地点：</label> <select id="country" name="country"
			onchange="getProvinces('','')"></select> <select id="province"
			name="province" onchange="getCities('')"></select> <select id="city"
			name="city">
		</select> <label> 具体地址：</label> <input type="text" name="detailAddress"
			id="detailAddress" value="" /> <br>
		<div id="mapContainer" style="height: 350px; width: 580px;"></div>
		<input id="latitude" name="latitude" type="hidden"> <input
			id="longitude" name="longitude" type="hidden"> <br>
		<textarea rows="5" cols="30" id="introduction" name="introduction"></textarea>


		<input type="hidden" name="submitToken"
			value='<skyline:sessionAttribute key="SESSION_SUBMIT_TOKEN"/>' /> <input
			type="submit" name="submit" value="提交"> <input type="reset"
			id="reset" value="取消">
	</form>
	<script type="text/javascript">
		(function($) {
			$(document).ready(function() {
				$('#discoverySpotForm').submit(function() {
					checkExit();
					return true;
				});
			});
		})(jQuery);
	</script>
</body>
</html>